package com.persondemo.videoappliction.ui.dianping;

import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.amap.api.location.AMapLocation;
import com.amap.api.location.AMapLocationClient;
import com.amap.api.location.AMapLocationClientOption;
import com.amap.api.location.AMapLocationListener;
import com.amap.api.location.AMapLocationQualityReport;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.google.gson.Gson;
import com.persondemo.videoappliction.R;
import com.persondemo.videoappliction.bean.DianPingBean;
import com.persondemo.videoappliction.bean.DianPingChoiceBean;
import com.persondemo.videoappliction.component.ApplicationComponent;
import com.persondemo.videoappliction.component.DaggerHttpComponent;
import com.persondemo.videoappliction.photo.utils.LogUtils;
import com.persondemo.videoappliction.ui.adapter.DianPingAdapter;
import com.persondemo.videoappliction.ui.adapter.DianpingPaixuAdapter;
import com.persondemo.videoappliction.ui.adapter.DianpingTypeAdapter;
import com.persondemo.videoappliction.ui.adapter.DianpingPriceAdapter;
import com.persondemo.videoappliction.ui.base.BaseFragment;
import com.persondemo.videoappliction.ui.dianping.city.CityChoiceActivity;
import com.persondemo.videoappliction.ui.dianping.contract.DianpingContract;
import com.persondemo.videoappliction.ui.dianping.presenter.DianPingPresenter;
import com.persondemo.videoappliction.utils.AnimationUtil;
import com.persondemo.videoappliction.utils.PreferenceUtil;
import com.persondemo.videoappliction.utils.T;
import com.persondemo.videoappliction.utils.Updataurl;
import com.persondemo.videoappliction.utils.ViewFindUtils;
import com.persondemo.videoappliction.widget.CustomLoadMoreView;
import com.persondemo.videoappliction.widget.SpaceItemDecoration;
import com.umeng.analytics.MobclickAgent;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.Unbinder;
import in.srain.cube.views.ptr.PtrClassicFrameLayout;
import in.srain.cube.views.ptr.PtrDefaultHandler;
import in.srain.cube.views.ptr.PtrFrameLayout;
import in.srain.cube.views.ptr.PtrHandler;

import static android.content.Context.INPUT_METHOD_SERVICE;

public class DianPingFragment extends BaseFragment<DianPingPresenter> implements DianpingContract.View {
    @BindView(R.id.location_btn)
    TextView locationBtn;
    @BindView(R.id.dingwei_img)
    ImageView dingweiImg;
    @BindView(R.id.window_search_search)
    ImageView windowSearchSearch;
    @BindView(R.id.window_search_edit)
    EditText windowSearchEdit;
    @BindView(R.id.merchant_sort)
    TextView merchantSort;
    @BindView(R.id.activity_merchant_down2)
    ImageView activityMerchantDown2;
    @BindView(R.id.activity_merchant_sort)
    RelativeLayout activityMerchantSort;
    @BindView(R.id.merchant_search)
    TextView merchantSearch;
    @BindView(R.id.activity_merchant_down4)
    ImageView activityMerchantDown4;
    @BindView(R.id.activity_merchant_search)
    RelativeLayout activityMerchantSearch;
    @BindView(R.id.merchant_screen)
    TextView merchantScreen;
    @BindView(R.id.activity_merchant_down3)
    ImageView activityMerchantDown3;
    @BindView(R.id.activity_merchant_screen)
    RelativeLayout activityMerchantScreen;
    @BindView(R.id.mRecyclerView)
    RecyclerView mRecyclerView;
    @BindView(R.id.SimpleMultiStateView)
    com.persondemo.videoappliction.widget.SimpleMultiStateView SimpleMultiStateView;
    @BindView(R.id.mPtrFrameLayout)
    PtrClassicFrameLayout mPtrFrameLayout;
    Unbinder unbinder;
    @BindView(R.id.dianping_dingwei_relate)
    RelativeLayout dianpingDingweiRelate;
    @BindView(R.id.view_liner)
    View viewLiner;
    private AMapLocationClient locationClient = null;
    private AMapLocationClientOption locationOption = null;
    AMapLocation mlocation = null;
    DianpingTypeAdapter ad01;//分类
    DianpingPaixuAdapter ad02;//综合排序
    DianpingPriceAdapter ad03_price;
    DianPingAdapter dianPingAdapter;
    List<DianPingChoiceBean.DataBean.TypelistBean> list01 = null;
    List<DianPingChoiceBean.DataBean.PaixuBean> list02 = null;
    List<DianPingChoiceBean.DataBean.ShaixuanBean> list3_price = null;
    List<DianPingBean.DataBean> dianPingBeanList = null;
    List<DianPingChoiceBean.DataBean.RecityBean> recityBeanList = null;
    private View view01, view03;
    private PopupWindow window01, window03;
    private RecyclerView cycler_dianping_01;
    private RecyclerView dianping03_01_recycler;
    int fromYDelta;
    String xlocation = "";//进度
    String ylocation = "";//维度
    String city = "";//城市
    String type = "";//分类如按摩 足浴等 ID
    String key = "";  //商圈名或商家名字搜索
    String paid = "";  //	排序ID 默认空
    String xid = "";//价格筛选ID
    int page = 1;

    public static DianPingFragment newInstance() {
        Bundle args = new Bundle();
        DianPingFragment fragment = new DianPingFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public int getContentLayout() {
        return R.layout.module_fragment_dianping;
    }

    @Override
    public void initInjector(ApplicationComponent appComponent) {
        DaggerHttpComponent.builder()
                .applicationComponent(appComponent)
                .build()
                .inject(this);
    }

    @Override
    public void bindView(View view, Bundle savedInstanceState) {
        mPtrFrameLayout.disableWhenHorizontalMove(true);
        mPtrFrameLayout.setPtrHandler(new PtrHandler() {
            @Override
            public boolean checkCanDoRefresh(PtrFrameLayout frame, View content, View header) {
                return PtrDefaultHandler.checkContentCanBePulledDown(frame, mRecyclerView, header);
            }

            @Override
            public void onRefreshBegin(PtrFrameLayout frame) {
                if (mPresenter != null) {
                    type = "";//分类如按摩 足浴等 ID
                    key = "";  //商圈名或商家名字搜索
                    paid = "";  //	排序ID 默认空
                    page = 1;
                    xid = "";//价格筛选ID
                    mPresenter.getpingce(xlocation, ylocation, type, key, paid, page + "", xid, city);
                    Log.i("lidaming", "走了吗");
                }
            }
        });
        mRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 1));
        dianPingAdapter = new DianPingAdapter(dianPingBeanList, getActivity());
        mRecyclerView.setAdapter(dianPingAdapter);
        dianPingAdapter.setEnableLoadMore(true);
        dianPingAdapter.setLoadMoreView(new CustomLoadMoreView());
        dianPingAdapter.openLoadAnimation(BaseQuickAdapter.ALPHAIN);
        dianPingAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                gotovideodetils(dianPingBeanList.get(position).getId() + "");
            }
        });
        dianPingAdapter.setOnLoadMoreListener(new BaseQuickAdapter.RequestLoadMoreListener() {
            @Override
            public void onLoadMoreRequested() {
                mPresenter.getpingce(xlocation, ylocation, type, key, paid, page + "", xid, city);
            }
        }, mRecyclerView);
        windowSearchEdit.setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_UP) {
                    ((InputMethodManager) getActivity().getSystemService(INPUT_METHOD_SERVICE))
                            .hideSoftInputFromWindow(getActivity().getCurrentFocus()
                                    .getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
                    //进行搜索操作的方法，在该方法中可以加入mEditSearchUser的非空判断
                    search();
                }
                return false;
            }
        });
    }

    private void search() {
        key = windowSearchEdit.getText().toString().trim();
        if (TextUtils.isEmpty(key)) {
            T.showShort(getActivity(), "输入框为空，请输入");
            return;
        } else {
            if (mPresenter != null) {
                changeColor(-1);
                type = "";//分类如按摩 足浴等 ID
                paid = "";  //	排序ID 默认空
                page = 1;
                xid = "";//价格筛选ID
                mPresenter.getpingce(xlocation, ylocation, type, key, paid, page + "", xid, city);
                Log.i("lidaming", "走了吗");
            }
        }

    }

    private void gotovideodetils(String id) {
        MobclickAgent.onEvent(getActivity(), "dianping");
        Intent intent = new Intent(getActivity(), DianPingDetilsActivity.class);
        Bundle bundle = new Bundle();
        bundle.putString("id", id);
        intent.putExtras(bundle);
        startActivity(intent);
    }

    @Override
    public void initData() {
        showLoadingDialog();
        initLocation();
        list01 = new ArrayList<>();
        list02 = new ArrayList<>();
        list3_price = new ArrayList<>();
        dianPingBeanList = new ArrayList<>();
        recityBeanList = new ArrayList<>();
    }

    /**
     * 修改点击后的颜色
     *
     * @param id
     */
    private void changeColor(int id) {
        merchantSort.setTextColor(Color.parseColor("#0f0f0f"));
        merchantSearch.setTextColor(Color.parseColor("#0f0f0f"));
        merchantScreen.setTextColor(Color.parseColor("#0f0f0f"));
        switch (id) {
            case 0:
                merchantSort.setTextColor(Color.parseColor("#ff9829"));
                break;
            case 1:
                merchantSearch.setTextColor(Color.parseColor("#ff9829"));
                break;
            case 2:
                merchantScreen.setTextColor(Color.parseColor("#ff9829"));
                break;
        }
    }

    //类型筛选
    private void showpop01() {
        view01 = getLayoutInflater().inflate(R.layout.module_pop_dianping01, null);
        cycler_dianping_01 = view01.findViewById(R.id.cycler_dianping_01);
        ad01 = new DianpingTypeAdapter(list01);
        cycler_dianping_01.setAdapter(ad01);
        cycler_dianping_01.setLayoutManager(new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL));
        ad01.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                for (int i = 0; i < list01.size(); i++) {
                    list01.get(i).setIscheck(false);
                }
                merchantSort.setText(list01.get(position).getName());
                list01.get(position).setIscheck(true);
                type = list01.get(position).getId() + "";
                if (mPresenter != null) {
                    showLoadingDialog();
                    page = 1;
                    mPresenter.getpingce(xlocation, ylocation, type, key, paid, page + "", xid, city);
                }
                window01.dismiss();
            }
        });
        window01 = new PopupWindow(view01, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        window01.setBackgroundDrawable(new BitmapDrawable());
        //将这两个属性设置为false，使点击popupwindow外面其他地方会消失
        window01.setOutsideTouchable(true);
        window01.setFocusable(true);
        setlayoutColor();
        //获取popupwindow高度确定动画开始位置
        int contentHeight = ViewFindUtils.getViewMeasuredHeight(view01);
        window01.showAsDropDown(viewLiner, 0, 0);
        fromYDelta = -contentHeight - 50;
        window01.getContentView().startAnimation(AnimationUtil.createInAnimation(getActivity(), fromYDelta));
        window01.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                getlayoutColor();
            }
        });

    }

    //类型筛选
    private void showpop02() {
        view01 = getLayoutInflater().inflate(R.layout.module_pop_dianping01, null);
        cycler_dianping_01 = view01.findViewById(R.id.cycler_dianping_01);
        ad02 = new DianpingPaixuAdapter(list02);
        cycler_dianping_01.setAdapter(ad02);
        cycler_dianping_01.setLayoutManager(new StaggeredGridLayoutManager(1, StaggeredGridLayoutManager.VERTICAL));
        ad02.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                for (int i = 0; i < list02.size(); i++) {
                    list02.get(i).setIscheck(false);
                }
                merchantSearch.setText(list02.get(position).getPaname());
                list02.get(position).setIscheck(true);
                paid = list02.get(position).getPaid() + "";
                if (mPresenter != null) {
                    page = 1;
                    mPresenter.getpingce(xlocation, ylocation, type, key, paid, page + "", xid, city);
                }

                window01.dismiss();
            }
        });
        window01 = new PopupWindow(view01, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        window01.setBackgroundDrawable(new BitmapDrawable());
        //将这两个属性设置为false，使点击popupwindow外面其他地方会消失
        window01.setOutsideTouchable(true);
        window01.setFocusable(true);
        setlayoutColor();
        //获取popupwindow高度确定动画开始位置
        int contentHeight = ViewFindUtils.getViewMeasuredHeight(view01);
        window01.showAsDropDown(viewLiner, 0, 0);
        fromYDelta = -contentHeight - 50;
        window01.getContentView().startAnimation(AnimationUtil.createInAnimation(getActivity(), fromYDelta));
        window01.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                getlayoutColor();
            }
        });

    }

    private void showpop03() {
        view03 = getLayoutInflater().inflate(R.layout.module_pop_dianping03, null);
        dianping03_01_recycler = view03.findViewById(R.id.dianping03_01_recycler);
        ad03_price = new DianpingPriceAdapter(list3_price);
        dianping03_01_recycler.setAdapter(ad03_price);
        dianping03_01_recycler.setLayoutManager(new GridLayoutManager(getActivity(), 4));
        dianping03_01_recycler.addItemDecoration(new SpaceItemDecoration(10));

        ad03_price.setOnItemChildClickListener(new BaseQuickAdapter.OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                for (int i = 0; i < list3_price.size(); i++) {
                    list3_price.get(i).setIscheck(false);
                }
                merchantScreen.setText(list3_price.get(position).getXname());
                list3_price.get(position).setIscheck(true);
                xid = list3_price.get(position).getXid() + "";
                if (mPresenter != null) {
                    page = 1;
                    mPresenter.getpingce(xlocation, ylocation, type, key, paid, page + "", xid, city);
                }
                ad03_price.notifyDataSetChanged();
                window03.dismiss();
            }
        });
        window03 = new PopupWindow(view03, LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        window03.setBackgroundDrawable(new BitmapDrawable());
        //将这两个属性设置为false，使点击popupwindow外面其他地方会消失
        window03.setOutsideTouchable(true);
        window03.setFocusable(true);
        setlayoutColor();
        //获取popupwindow高度确定动画开始位置
        int contentHeight = ViewFindUtils.getViewMeasuredHeight(view03);
        window03.showAsDropDown(viewLiner, 0, 0);
        fromYDelta = -contentHeight - 50;
        window03.getContentView().startAnimation(AnimationUtil.createInAnimation(getActivity(), fromYDelta));
        window03.setOnDismissListener(new PopupWindow.OnDismissListener() {
            @Override
            public void onDismiss() {
                getlayoutColor();
            }
        });
    }

    /*
     * 改变背景颜色亮度,当点击window让屏幕变暗
     */
    protected void setlayoutColor() {
        Float A = (float) .10f;
        WindowManager.LayoutParams lp = getActivity().getWindow().getAttributes();
        lp.alpha = 0.7f;
        getActivity().getWindow().setAttributes(lp);
    }

    /*
     * 恢复背景颜色亮度
     */
    protected void getlayoutColor() {
        Float A = (float) 1f;
        WindowManager.LayoutParams lp = getActivity().getWindow().getAttributes();
        lp.alpha = 1f;
        getActivity().getWindow().setAttributes(lp);
    }

    /**
     * 初始化定位
     *
     * @author hongming.wang
     * @since 2.8.0
     */
    private void initLocation() {
        //初始化client
        locationClient = new AMapLocationClient(getActivity().getApplicationContext());
        locationOption = getDefaultOption();
        //设置定位参数
        locationClient.setLocationOption(locationOption);
        // 设置定位监听
        locationClient.setLocationListener(locationListener);
        startLocation();
    }

    /**
     * 默认的定位参数
     *
     * @author hongming.wang
     * @since 2.8.0
     */
    private AMapLocationClientOption getDefaultOption() {
        AMapLocationClientOption mOption = new AMapLocationClientOption();
        mOption.setLocationMode(AMapLocationClientOption.AMapLocationMode.Hight_Accuracy);//可选，设置定位模式，可选的模式有高精度、仅设备、仅网络。默认为高精度模式
        mOption.setGpsFirst(false);//可选，设置是否gps优先，只在高精度模式下有效。默认关闭
        mOption.setHttpTimeOut(30000);//可选，设置网络请求超时时间。默认为30秒。在仅设备模式下无效
        mOption.setInterval(2000);//可选，设置定位间隔。默认为2秒
        mOption.setNeedAddress(true);//可选，设置是否返回逆地理地址信息。默认是true
        mOption.setOnceLocation(false);//可选，设置是否单次定位。默认是false
        mOption.setOnceLocationLatest(false);//可选，设置是否等待wifi刷新，默认为false.如果设置为true,会自动变为单次定位，持续定位时不要使用
        AMapLocationClientOption.setLocationProtocol(AMapLocationClientOption.AMapLocationProtocol.HTTP);//可选， 设置网络请求的协议。可选HTTP或者HTTPS。默认为HTTP
        mOption.setSensorEnable(false);//可选，设置是否使用传感器。默认是false
        mOption.setWifiScan(true); //可选，设置是否开启wifi扫描。默认为true，如果设置为false会同时停止主动刷新，停止以后完全依赖于系统刷新，定位位置可能存在误差
        mOption.setLocationCacheEnable(true); //可选，设置是否使用缓存定位，默认为true
        mOption.setGeoLanguage(AMapLocationClientOption.GeoLanguage.DEFAULT);//可选，设置逆地理信息的语言，默认值为默认语言（根据所在地区选择语言）
        return mOption;
    }

    /**
     * 定位监听
     */
    AMapLocationListener locationListener = new AMapLocationListener() {
        @Override
        public void onLocationChanged(AMapLocation location) {
            if (null != location) {
                StringBuffer sb = new StringBuffer();
                //errCode等于0代表定位成功，其他的为定位失败，具体的可以参照官网定位错误码说明
                if (location.getErrorCode() == 0) {
                    sb.append("定位成功" + "\n");
                    sb.append("定位类型: " + location.getLocationType() + "\n");
                    sb.append("经    度    : " + location.getLongitude() + "\n");
                    sb.append("纬    度    : " + location.getLatitude() + "\n");
                    sb.append("精    度    : " + location.getAccuracy() + "米" + "\n");
                    sb.append("提供者    : " + location.getProvider() + "\n");
                    sb.append("速    度    : " + location.getSpeed() + "米/秒" + "\n");
                    sb.append("角    度    : " + location.getBearing() + "\n");
                    // 获取当前提供定位服务的卫星个数
                    sb.append("星    数    : " + location.getSatellites() + "\n");
                    sb.append("国    家    : " + location.getCountry() + "\n");
                    sb.append("省            : " + location.getProvince() + "\n");
                    sb.append("市            : " + location.getCity() + "\n");
                    sb.append("城市编码 : " + location.getCityCode() + "\n");
                    sb.append("区            : " + location.getDistrict() + "\n");
                    sb.append("区域 码   : " + location.getAdCode() + "\n");
                    sb.append("地    址    : " + location.getAddress() + "\n");
                    sb.append("兴趣点    : " + location.getPoiName() + "\n");
                    //定位完成的时间
                    sb.append("定位时间: " + Utils.formatUTC(location.getTime(), "yyyy-MM-dd HH:mm:ss") + "\n");
                } else {
                    //定位失败
                    sb.append("定位失败" + "\n");
                    sb.append("错误码:" + location.getErrorCode() + "\n");
                    sb.append("错误信息:" + location.getErrorInfo() + "\n");
                    sb.append("错误描述:" + location.getLocationDetail() + "\n");
                }
                sb.append("***定位质量报告***").append("\n");
                sb.append("* WIFI开关：").append(location.getLocationQualityReport().isWifiAble() ? "开启" : "关闭").append("\n");
                sb.append("* GPS状态：").append(getGPSStatusString(location.getLocationQualityReport().getGPSStatus())).append("\n");
                sb.append("* GPS星数：").append(location.getLocationQualityReport().getGPSSatellites()).append("\n");
                sb.append("* 网络类型：" + location.getLocationQualityReport().getNetworkType()).append("\n");
                sb.append("* 网络耗时：" + location.getLocationQualityReport().getNetUseTime()).append("\n");
                sb.append("****************").append("\n");
                //定位之后的回调时间
                sb.append("回调时间: " + Utils.formatUTC(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss") + "\n");
                //解析定位结果，
                String result = sb.toString();
                LogUtils.d("dingwei", result);
                mlocation = location;
                if (mlocation != null) {
                    LocationBean locationBean = new LocationBean();
                    locationBean.setCity(location.getCity());
                    locationBean.setLatitude(location.getLatitude());
                    locationBean.setLongitude(location.getLongitude());
                    stopLocation();
                    Updataurl.setUrl(location.getCity());
                    locationBtn.setText(mlocation.getCity());
                    PreferenceUtil.put("city", mlocation.getCity());
                    PreferenceUtil.put("x", mlocation.getLongitude() + "");
                    PreferenceUtil.put("y", mlocation.getLatitude() + "");
                    xlocation = mlocation.getLongitude() + "";
                    ylocation = mlocation.getLatitude() + "";
                    city = mlocation.getCity();
                    if (mPresenter != null) {
                        mPresenter.getchoice(mlocation.getCity());
                        mPresenter.getpingce(xlocation, ylocation, type, key, paid, page + "", xid, city);
                    }
                }
            } else {
                city = PreferenceUtil.getString("city", "");
                xlocation = PreferenceUtil.getString("x", "");
                ylocation = PreferenceUtil.getString("y", "");
                if (mPresenter != null) {
                    mPresenter.getchoice(city);
                    mPresenter.getpingce(xlocation, ylocation, type, key, paid, page + "", xid, city);
                }
                locationBtn.setText("定位失败");
            }
        }
    };

    /**
     * 停止定位
     *
     * @author hongming.wang
     * @since 2.8.0
     */
    private void stopLocation() {
        // 停止定位
        locationClient.stopLocation();
    }

    /**
     * 获取GPS状态的字符串
     *
     * @param statusCode GPS状态码
     * @return
     */
    private String getGPSStatusString(int statusCode) {
        String str = "";
        switch (statusCode) {
            case AMapLocationQualityReport.GPS_STATUS_OK:
                str = "GPS状态正常";
                break;
            case AMapLocationQualityReport.GPS_STATUS_NOGPSPROVIDER:
                str = "手机中没有GPS Provider，无法进行GPS定位";
                break;
            case AMapLocationQualityReport.GPS_STATUS_OFF:
                str = "GPS关闭，建议开启GPS，提高定位质量";
                break;
            case AMapLocationQualityReport.GPS_STATUS_MODE_SAVING:
                str = "选择的定位模式中不包含GPS定位，建议选择包含GPS定位的模式，提高定位质量";
                break;
            case AMapLocationQualityReport.GPS_STATUS_NOGPSPERMISSION:
                str = "没有GPS定位权限，建议开启gps定位权限";
                break;
        }
        return str;
    }

    /**
     * 开始定位
     *
     * @author hongming.wang
     * @since 2.8.0
     */
    private void startLocation() {
        //根据控件的选择，重新设置定位参数
//        resetOption();
        // 设置定位参数
        locationClient.setLocationOption(locationOption);
        // 启动定位
        locationClient.startLocation();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        // TODO: inflate a fragment view
        View rootView = super.onCreateView(inflater, container, savedInstanceState);
        unbinder = ButterKnife.bind(this, rootView);
        return rootView;
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }

    @OnClick({R.id.dianping_dingwei_relate, R.id.window_search_edit, R.id.activity_merchant_sort, R.id.activity_merchant_search, R.id.activity_merchant_screen})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.dianping_dingwei_relate:
                //第二个参数为请求码，可以根据业务需求自己编号
                startActivityForResult(new Intent(getActivity(), CityChoiceActivity.class), 1);
//                startActivity(new Intent(getActivity(), CityChoiceActivity.class));
                break;
            case R.id.window_search_edit:
                break;
            case R.id.activity_merchant_sort:
                changeColor(0);
                showpop01();
                break;
            case R.id.activity_merchant_search:
                showpop02();
                changeColor(1);
                break;
            case R.id.activity_merchant_screen:
                changeColor(2);
                showpop03();
                break;
        }
    }

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == 1) {
            if (resultCode == RESULT_OK) {
                String city1 = "";
                city1 = data.getStringExtra("city");
                if (!TextUtils.isEmpty(city1)) {
                    city = city1;
                    page=1;
                    type = "";//分类如按摩 足浴等 ID
                    key = "";  //商圈名或商家名字搜索
                    paid = "";  //	排序ID 默认空
                    page = 1;
                    xid = "";//价格筛选ID
                    locationBtn.setText(city);
                    if (mPresenter != null) {
                        showLoadingDialog();
                        mPresenter.getpingce(xlocation, ylocation, type, key, paid, page + "", xid, city);
                    }
                }

            }
        }
    }


    @Override
    public void loadchoice(DianPingChoiceBean dianPingChoiceBean) {
        hideLoadingDialog();
        if (dianPingChoiceBean == null) {
            showFaild();
            return;
        }
        if (dianPingChoiceBean.getStatus() == 1) {
            if (dianPingChoiceBean.getData().getTypelist() != null && dianPingChoiceBean.getData().getTypelist().size() > 0) {
                list01 = dianPingChoiceBean.getData().getTypelist();
            }
            if (dianPingChoiceBean.getData().getPaixu() != null && dianPingChoiceBean.getData().getPaixu().size() > 0) {
                list02 = dianPingChoiceBean.getData().getPaixu();
            }
            if (dianPingChoiceBean.getData().getShaixuan() != null && dianPingChoiceBean.getData().getShaixuan().size() > 0) {
                list3_price = dianPingChoiceBean.getData().getShaixuan();
            }
            if (dianPingChoiceBean.getData().getRecity() != null && dianPingChoiceBean.getData().getRecity().size() > 0) {
                recityBeanList = dianPingChoiceBean.getData().getRecity();
                Gson gson = new Gson();
                String a = gson.toJson(recityBeanList);
                PreferenceUtil.put("chengshi", a);
            }
        } else {
            T.showShort(getActivity(), dianPingChoiceBean.getMsg());
        }
    }

    @Override
    public void loadpingce(DianPingBean dianPingBean) {
        Log.i("RetrofitConfig", "2");
        hideLoadingDialog();
        if (dianPingBean == null) {
            showFaild();
            return;
        }
        if (dianPingBean.getData() == null || dianPingBean.getData().size() == 0) {
            hideLoadingDialog();
            T.showShort(getActivity(), "没有更多数据了！");
//            baseVideoAdapter.setEmptyView();
            return;
        }
        if (dianPingBean.getData() != null && dianPingBean.getStatus() == 1) {
            if (dianPingBean.getData().size() > 0) {
                dianPingBeanList.clear();
                dianPingBeanList = dianPingBean.getData();
                dianPingAdapter.setNewData(dianPingBeanList);
                mPtrFrameLayout.refreshComplete();
                showSuccess();
                page++;
                if (dianPingBeanList.size() < 1) {
                    dianPingAdapter.loadMoreEnd();
                }
            }
        }
    }

    @Override
    public void loadpingcemore(DianPingBean dianPingBean) {
        if (dianPingBean.getData() == null || dianPingBean.getData().size() == 0) {
            dianPingAdapter.loadMoreEnd();
            T.showShort(getActivity(), "没有更多数据了！");
            return;
        } else {
            page++;
            dianPingAdapter.addData(dianPingBean.getData());
            dianPingAdapter.loadMoreComplete();
        }
    }
}
